package com.darren.framework.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.darren.framework.entity.City;
import com.darren.framework.entity.Province;
import com.darren.framework.entity.ResponseJSON;
import com.darren.framework.service.CityService;
import com.darren.framework.service.ProvinceService;
import com.darren.framework.utils.Constant;

@Controller
@RequestMapping("/place")
public class PlaceAction extends BaseAction{	
	
	@Resource
	private ProvinceService provinceService;
	
	@Resource
	private CityService cityService;
	
	@ResponseBody
	@RequestMapping("/provinces")
	public  ResponseJSON getProvinces(HttpServletRequest request){
		ResponseJSON responseJson = new ResponseJSON();			
		List<Province> provinces = provinceService.getAll();
		responseJson.setData(provinces);
		return responseJson;
	}
	
	
	
	@ResponseBody
	@RequestMapping("/province/{id}")
	public  ResponseJSON getProvince(@PathVariable(name="id",required=true) Long  id,HttpServletRequest request){
		ResponseJSON responseJson = new ResponseJSON();			
		Province province = provinceService.findById(id);
		responseJson.setData(province);
		return responseJson;
	}

	@ResponseBody
	@RequestMapping("/cities")
	public  ResponseJSON getCities(HttpServletRequest request){
		ResponseJSON responseJson = new ResponseJSON();			
		List<City> cities = cityService.getAll();
		responseJson.setData(cities);
		return responseJson;
	}
	
	@ResponseBody
	@RequestMapping("/city/{id}")
	public  ResponseJSON getCity(@PathVariable(name="id",required=true) Long  id,HttpServletRequest request){
		ResponseJSON responseJson = new ResponseJSON();			
		City city = cityService.findById(id);
		responseJson.setData(city);
		return responseJson;
	}

}
